package com.beamfield.controller.manage.sys;

import com.beamfield.common.ApiResult;
import com.beamfield.common.PageResult;
import com.beamfield.controller.common.BaseController;
import com.beamfield.model.LabParameterRep;
import com.beamfield.service.manage.lab.LabParameterRepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author Zephyr
 * @description:
 * @date 2019/6/18
 */
@RequestMapping("/cms/sys/labParameterRep")
@Controller
public class LabParameterRepController extends BaseController {
    @Autowired
    private LabParameterRepService labParameterRepService;

    @RequestMapping(value = "/lab_parameter_rep")
    public ModelAndView document(){
        return new ModelAndView();
    }

    @RequestMapping(value = "save")
    @ResponseBody
    public ApiResult save(LabParameterRep labParameterRep, HttpServletRequest request){
        Long userId = super.getUserId(request);
        labParameterRep.setAddtime(new Date());
        labParameterRep.setOperator(userId);
        labParameterRepService.save(labParameterRep);
        return new ApiResult();
    }

    @RequestMapping("update")
    @ResponseBody
    public ApiResult update(HttpServletRequest request, LabParameterRep labParameterRep){
        Long userId = super.getUserId(request);
        labParameterRep.setUpdater(userId);
        labParameterRep.setUpdatetime(new Date());
        labParameterRepService.update(labParameterRep);
        return new ApiResult();
    }

    @RequestMapping("delete")
    @ResponseBody
    public ApiResult delete(Long id){
        labParameterRepService.delete(id);
        return new ApiResult();
    }

    @RequestMapping("page")
    @ResponseBody
    public PageResult page(HttpServletRequest request){
        Long beamId = super.getBeamId(request);
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        String queryWords = request.getParameter("queryWords");
        String pid = request.getParameter("pid");
        String parameter = request.getParameter("parameter");

        return labParameterRepService.page(beamId, offset, limit, queryWords, pid, parameter);
    }

    @RequestMapping("getAll")
    @ResponseBody
    public PageResult getAll(HttpServletRequest request){
        Long beamId = super.getBeamId(request);
        return labParameterRepService.getAll(beamId);
    }

    @RequestMapping("up")
    @ResponseBody
    public ApiResult up(HttpServletRequest request){
        String id = request.getParameter("id");
        return labParameterRepService.up(id);
    }

    @RequestMapping("down")
    @ResponseBody
    public ApiResult down(HttpServletRequest request){
        String id = request.getParameter("id");
        return labParameterRepService.down(id);
    }
}
